﻿<%@ CodePage = 65001 %>

<!--#include file="includes/database.asp" -->
<!--#include file="includes/global_varaiable.asp" -->
<!--#include file="giochieu_info.asp" -->

<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.addHeader "cache-control", "no-cache"
Response.addHeader "cache-control", "no-store"
Response.CacheControl = "no-cache"
%>

<%
Response.Buffer = True

ewSessionMessage = "Message"

' Load Key Parameters
sKey = "": bSingleDelete = True
x_GiochieuID = Request.QueryString("GiochieuID")
If x_GiochieuID <> "" Then
	If sKey <> "" Then sKey = sKey & ","
	sKey = sKey & x_GiochieuID
Else
	bSingleDelete = False
End If
If Not bSingleDelete Then
	sKey = Request.Form("key_d")
End If
If sKey = "" Or IsNull(sKey) Then Response.Redirect "giochieu_list.asp"
arRecKey = Split(sKey&"", ",")
i = 0
Do While i <= UBound(arRecKey)
	sDbWhere = sDbWhere & "("

	' Remove spaces
	sRecKey = Trim(arRecKey(i+0))

	' Build the SQL
	sDbWhere = sDbWhere & "[SessionID]=" & sRecKey & " AND "
	If Right(sDbWhere, 5) = " AND " Then sDbWhere = Left(sDbWhere, Len(sDbWhere)-5) & ") OR "
	i = i + 1
Loop
If Right(sDbWhere, 4) = " OR " Then sDbWhere = Left(sDbWhere, Len(sDbWhere)-4)

' Get action
sAction = Request.Form("a_delete")
If sAction = "" Or IsNull(sAction) Then
	sAction = "D"	' Delete record directly
End If

Select Case sAction
	Case "I": ' Display
		If LoadRecordCount(sDbWhere) <= 0 Then
			adoCon.Close ' Close adoConection
			Set adoCon = Nothing
			Response.Clear
			Response.Redirect "giochieu_list.asp"
		End If
	Case "D": ' Delete
		If DeleteData(sDbWhere) Then
			Session(ewSessionMessage) = "Xóa thành công"
			adoCon.Close ' Close adoConection
			Set adoCon = Nothing
			Response.Clear
			Response.Redirect "giochieu_list.asp"
		End If
End Select
%>
<!--#include file="header.asp"-->
<p><span class="aspmaker">Delete from TABLE: GIOCHIEU<br><br><a href="giochieu_list.asp">Back to List</a></span></p>
<form action="giochieu_xoa.asp" method="post">
<p>
<input type="hidden" name="a_delete" value="D">
<input type="hidden" name="key_d" value="<%= sKey %>">
<table class="ewTable">
	<tr class="ewTableHeader">
		<td valign="top"><span>Session ID</span></td>
		<td valign="top"><span>Description</span></td>
		<td valign="top"><span>Hour Start</span></td>
		<td valign="top"><span>Minute Start</span></td>
	</tr>
<%
nRecCount = 0
i = 0
Do While i <= UBound(arRecKey)
	nRecCount = nRecCount + 1

	' Set row color
	sItemRowClass = " class=""ewTableRow"""

	' Display alternate color for rows
	If nRecCount Mod 2 <> 0 Then
		sItemRowClass = " class=""ewTableAltRow"""
	End If
	sRecKey = Trim(arRecKey(i+0))
	x_GiochieuID = sRecKey
	If LoadData() Then
%>
	<tr<%=sItemRowClass%>>
		<td><span>
<% Response.Write x_GiochieuID %>
</span></td>
		<td><span>
<% Response.Write x_Mota %>
</span></td>
		<td><span>
<% Response.Write x_gioBD %>
</span></td>
		<td><span>
<% Response.Write x_phutBD %>
</span></td>
	</tr>
<%
	End If
	i = i + 1
Loop
%>
</table>
<p>
<input type="submit" name="Action" value="CONFIRM DELETE">
</form>
<%
adoCon.Close ' Close adoConection
Set adoCon = Nothing
%>
<!--#include file="footer.asp"-->
<%

'-------------------------------------------------------------------------------
' Function LoadData
' - Load Data based on Key Value
' - Variables setup: field variables

Function LoadData()
	Dim rs, sSql, sFilter
	sFilter = ewSqlKeyWhere
	sFilter = Replace(sFilter, "@GiochieuID", AdjustSql(x_GiochieuID)) ' Replace key value
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.Open sSql, adoCon
	If rs.Eof Then
		LoadData = False
	Else
		LoadData = True
		rs.MoveFirst

		' Get the field contents
		x_GiochieuID = rs("GiochieuID")
		x_Mota = rs("Mota")
		x_gioBD = rs("gioBD")
		x_phutBD = rs("phutBD")
	End If
	rs.Close
	Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function LoadRecordCount
' - Load Record Count based on input sql criteria sqlKey

Function LoadRecordCount(sqlKey)
	Dim rs, sSql, sFilter
	sFilter = sqlKey
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.CursorLocation = 3
	rs.Open sSql, adoCon, 1, 2
	LoadRecordCount = rs.RecordCount
	rs.Close
	Set rs = Nothing
End Function
%>
<%

'-------------------------------------------------------------------------------
' Function DeleteData
' - Delete Records based on input sql criteria sqlKey

Function DeleteData(sqlKey)
	Dim rs, sSql, sFilter
	sFilter = sqlKey
	sSql = ewBuildSql(ewSqlSelect, ewSqlWhere, ewSqlGroupBy, ewSqlHaving, ewSqlOrderBy, sFilter, "")
	Set rs = Server.CreateObject("ADODB.Recordset")
	rs.CursorLocation = 3
	rs.Open sSql, adoCon, 1, 2

	' Clone old rs object
	Dim rsold
	Set rsold = rs.Clone(1)
	rsold.Requery

	' Call recordset deleting event
	DeleteData = Recordset_Deleting(rs)
	If DeleteData Then
		Do While Not rs.Eof
			rs.Delete
			rs.MoveNext
		Loop
	End If
	rs.Close
	Set rs = Nothing

	' Call recordset deleted event
	If DeleteData Then
		Call Recordset_Deleted(rsold)
	End If
	rsold.Close
	Set rsold = Nothing
End Function

'-------------------------------------------------------------------------------
' Recordset deleting event

Function Recordset_Deleting(rsold)
	On Error Resume Next

	' Please enter your customized codes here
	Recordset_Deleting = True
End Function

'-------------------------------------------------------------------------------
' Recordset deleted event

Sub Recordset_Deleted(rsold)
	On Error Resume Next
End Sub
%>
